package com.mybatisplus.mp.controller;

import com.mybatisplus.mp.mapper.UserMapper;
import com.mybatisplus.mp.pojo.User;
import com.mybatisplus.mp.service.UserCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CacheController {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private UserCacheService userCacheService;
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/cache/{id}")
    public User queryByid(@PathVariable("id") int id) {
        User user = userCacheService.queryByid2(id);
        return user;

    }

    @GetMapping("/cache2")
    public void queryByid2() {
        User user = User.builder().name("张三").age(3).build();
        redisTemplate.opsForValue().set("id",user);

    }
}
